package com.xmall.sys.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmall.sys.define.dto.operateLog.OperateLogDto;
import com.xmall.sys.define.request.operateLog.OperateLogListPageQueryRequest;
import com.xmall.sys.entity.OperateLog;
import com.xmall.sys.mapper.OperateLogMapper;
import com.xmall.sys.service.IOperateLogService;
import com.xmall.sys.utils.ConvertUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 操作日志 服务实现类
 * </p>
 *
 * @author xmall
 * @since 2023-12-18
 */
@Service
public class OperateLogServiceImpl extends ServiceImpl<OperateLogMapper, OperateLog> implements IOperateLogService {

    /**
     * 分页列表
     */
    @Override
    public Page<OperateLogDto> listPage(OperateLogListPageQueryRequest request) {
        Page<OperateLogDto> result = new Page<>();
        QueryWrapper query = new QueryWrapper();
        query.like(StrUtil.isNotBlank(request.getOperateName()), "operate_name", request.getOperateName());
        query.like(StrUtil.isNotBlank(request.getOperateAccount()), "operate_account", request.getOperateAccount());
        query.like(StrUtil.isNotBlank(request.getServiceName()), "service_name", request.getServiceName());
        query.eq(null != request.getOperatePlatform(), "operate_platform", request.getOperatePlatform());
        query.eq(null != request.getOperateType(), "operate_type", request.getOperateType());
        query.eq(null != request.getHasException(), "has_exception", request.getHasException());
        query.orderByDesc("request_time");

        Page<OperateLog> page = this.page(new Page(request.getPage(), request.getPageSize()), query);

        BeanUtils.copyProperties(page, result);
        result.setRecords(ConvertUtils.OperateLogModule.INSTANCE.toDtoList(page.getRecords()));
        return result;
    }
}
